package clock._11.cheremisinova;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;
import java.util.GregorianCalendar;
import javax.imageio.ImageIO;
import javax.swing.JPanel;
import javax.swing.Timer;

public class Draw extends JPanel {

    private int h;
    private int min;
    private int sec;
    Color lime = new Color(204, 255, 0);
    Color frog = new Color(52, 191, 26);

    public void drawI(Graphics g) {
        Graphics2D numberI = (Graphics2D) g;
        numberI.setColor(lime);
        numberI.setStroke(new BasicStroke(2));
        numberI.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        numberI.drawLine(-5, 8, 5, 8);
        numberI.drawLine(-5, -8, 5, -8);
        numberI.drawLine(0, 8, 0, -8);
    }

    public void drawV(Graphics g) {
        Graphics2D numberV = (Graphics2D) g.create();
        numberV.setColor(lime);
        numberV.setStroke(new BasicStroke(2));
        numberV.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        numberV.drawLine(-5, 8, 5, 8);
        numberV.drawLine(-5, -8, 5, -8);
        numberV.drawLine(-3, -8, 0, 8);
        numberV.drawLine(0, 8, 3, -8);
    }

    public void drawX(Graphics g) {
        Graphics2D numberX = (Graphics2D) g.create();
        numberX.setColor(lime);
        numberX.setStroke(new BasicStroke(2));
        numberX.drawLine(-5, 8, 5, 8);
        numberX.drawLine(-5, -8, 5, -8);
        numberX.drawLine(-3, 8, 3, -8);
        numberX.drawLine(3, 8, -3, -8);
    }

    public void drawStr(Graphics g) {
        Graphics2D second = (Graphics2D) g.create();
        second.setColor(frog);
        second.setStroke(new BasicStroke(2));
        second.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        second.drawLine(0, 0, 0, -50);
    }

    public void drawStr2(Graphics g) {
        Graphics2D minute = (Graphics2D) g.create();
        minute.setColor(frog);
        minute.setStroke(new BasicStroke(4));
        minute.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        minute.drawLine(0, 0, 0, -50);
    }

    public void drawStr3(Graphics g) {
        Graphics2D hour = (Graphics2D) g.create();
        hour.setColor(frog);
        hour.setStroke(new BasicStroke(6));
        hour.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        hour.drawLine(0, 0, 0, -30);
    }

    public Draw() {
        Timer t = new Timer(1000, new ActionListener() {

            public void actionPerformed(ActionEvent e) {
                GregorianCalendar gcal = new GregorianCalendar();
                h = gcal.get(GregorianCalendar.HOUR);
                min = gcal.get(GregorianCalendar.MINUTE);
                sec = gcal.get(GregorianCalendar.SECOND);
                repaint();
            }
        });
        t.start();
    }

    @Override
    protected void paintComponent(Graphics g) {

        Graphics2D circle = (Graphics2D) g;
        circle.fillRect(0, 0, 610, 480);
        g.translate(300, 200);

        InputStream im = Draw.class.getResourceAsStream("res/fon.jpg");
        Image fon = null;
        try {
            fon = ImageIO.read(im);
        } catch (IOException ex) {
            System.out.println("error");
        }

        circle.drawImage(fon, -445, -220, null);

        int R = 80;
        int R2 = 70;
        int R3 = 67;
        int R4 = 3;

        circle.setStroke(new BasicStroke(15));
        circle.setColor(frog);
        circle.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        circle.drawOval(-R, -R, 2 * R, 2 * R);

        circle.setStroke(new BasicStroke(10));
        circle.setColor(lime);
        circle.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        circle.drawOval(-R2, -R2, 2 * R2, 2 * R2);


        circle.setColor(Color.white);
        circle.fillOval(-R3, -R3, 2 * R3, 2 * R3);

        circle.setColor(lime);
        circle.fillOval(-R4, -R4, 2 * R4, 2 * R4);

        for (int i = 1; i < 13; i++) {
            if (i == 1) {
                Graphics2D number1 = (Graphics2D) g.create();
                number1.translate(30, -45);
                number1.rotate(Math.PI / 6);
                drawI(number1);
                number1.dispose();
            }
            if (i == 2) {
                Graphics2D number2 = (Graphics2D) g.create();
                number2.translate(46, -30);
                number2.rotate(Math.PI / 3);
                drawI(number2);
                number2.dispose();
                Graphics2D number22 = (Graphics2D) g.create();
                number22.translate(50, -24);
                number22.rotate(Math.PI / 3);
                drawI(number22);
                number22.dispose();
            }
            if (i == 3) {
                Graphics2D number3 = (Graphics2D) g.create();
                number3.translate(55, 5);
                number3.rotate(Math.PI / 2);
                drawI(number3);
                number3.dispose();

                Graphics2D number32 = (Graphics2D) g.create();
                number32.translate(55, 0);
                number32.rotate(Math.PI / 2);
                drawI(number32);
                number32.dispose();

                Graphics2D number33 = (Graphics2D) g.create();
                number33.translate(55, -5);
                number33.rotate(Math.PI / 2);
                drawI(number33);
                number33.dispose();
            }
            if (i == 4) {
                Graphics2D number4 = (Graphics2D) g.create();
                number4.translate(50, 23);
                number4.rotate(2 * Math.PI / 3);
                drawI(number4);
                number4.dispose();

                Graphics2D number42 = (Graphics2D) g.create();
                number42.translate(45, 32);
                number42.rotate(2 * Math.PI / 3);
                drawV(number42);
                number42.dispose();
            }
            if (i == 5) {
                Graphics2D number5 = (Graphics2D) g.create();
                number5.translate(27, 48);
                number5.rotate(5 * Math.PI / 6);
                drawV(number5);
                number5.dispose();
            }
            if (i == 6) {
                Graphics2D number6 = (Graphics2D) g.create();
                number6.translate(4, 53);
                number6.rotate(-Math.PI);
                drawV(number6);
                number6.dispose();
                Graphics2D number62 = (Graphics2D) g.create();
                number62.translate(-4, 53);
                number62.rotate(-Math.PI);
                drawI(number62);
                number62.dispose();
            }
            if (i == 7) {
                Graphics2D number7 = (Graphics2D) g.create();
                number7.translate(-22, 51);
                number7.rotate(-5 * Math.PI / 6);
                drawV(number7);
                number7.dispose();

                Graphics2D number72 = (Graphics2D) g.create();
                number72.translate(-26, 48);
                number72.rotate(-5 * Math.PI / 6);
                drawI(number72);
                number72.dispose();

                Graphics2D number73 = (Graphics2D) g.create();
                number73.translate(-29, 46);
                number73.rotate(-5 * Math.PI / 6);
                drawI(number73);
                number73.dispose();
            }

            if (i == 8) {
                Graphics2D number8 = (Graphics2D) g.create();
                number8.translate(-43, 35);
                number8.rotate(-2 * Math.PI / 3);
                drawV(number8);
                number8.dispose();

                Graphics2D number82 = (Graphics2D) g.create();
                number82.translate(-46, 31);
                number82.rotate(-2 * Math.PI / 3);
                drawI(number82);
                number82.dispose();

                Graphics2D number83 = (Graphics2D) g.create();
                number83.translate(-48, 28);
                number83.rotate(-2 * Math.PI / 3);
                drawI(number83);
                number83.dispose();

                Graphics2D number84 = (Graphics2D) g.create();
                number84.translate(-50, 23);
                number84.rotate(-2 * Math.PI / 3);
                drawI(number84);
                number84.dispose();


            }
            if (i == 9) {
                Graphics2D number9 = (Graphics2D) g.create();
                number9.translate(-55, -4);
                number9.rotate(-Math.PI / 2);
                drawI(number9);
                number9.dispose();

                Graphics2D number92 = (Graphics2D) g.create();
                number92.translate(-55, 4);
                number92.rotate(-Math.PI / 2);
                drawX(number92);
                number92.dispose();
            }
            if (i == 10) {
                Graphics2D number10 = (Graphics2D) g.create();
                number10.translate(-49, -27);
                number10.rotate(-Math.PI / 3);
                drawX(number10);
                number10.dispose();
            }
            if (i == 11) {
                Graphics2D number11 = (Graphics2D) g.create();
                number11.translate(-34, -43);
                number11.rotate(-Math.PI / 6);
                drawX(number11);
                number11.dispose();

                Graphics2D number112 = (Graphics2D) g.create();
                number112.translate(-27, -47);
                number112.rotate(-Math.PI / 6);
                drawI(number112);
                number112.dispose();


            }
            if (i == 12) {
                Graphics2D number12 = (Graphics2D) g.create();
                number12.translate(-5, -53);
                drawX(number12);
                number12.dispose();

                Graphics2D number122 = (Graphics2D) g.create();
                number122.translate(2, -53);
                drawI(number122);
                number122.dispose();

                Graphics2D number123 = (Graphics2D) g.create();
                number123.translate(7, -53);
                drawI(number123);
                number123.dispose();
            }

            Graphics2D second2 = (Graphics2D) g.create();
            second2.rotate(sec * Math.PI / 30);
            drawStr(second2);
            second2.dispose();

            Graphics2D minute2 = (Graphics2D) g.create();
            minute2.rotate(min * Math.PI / 30);
            drawStr2(minute2);
            minute2.dispose();

            Graphics2D hour2 = (Graphics2D) g.create();
            hour2.rotate(h * Math.PI / 6);
            drawStr3(hour2);
            hour2.dispose();

            Graphics2D center = (Graphics2D) g.create();
            center.setColor(frog);
            center.fillOval(-2, -3, 5, 5);
        }
    }
}
